package com.geng.serviceImpl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.geng.dao.DeptMapper;
import com.geng.pojo.Dept;
import com.geng.service.DeptService;

import tk.mybatis.mapper.entity.Example;

@Service
public class DeptServiceImpl implements DeptService {
	@Autowired
	private DeptMapper deptMapper;
	
	@Override
	public List findAllDept() {
		return deptMapper.selectAll();
	}

	@Override
	public List queryDept(String dName,String loc) {
		Example example= new Example(Dept.class);
		Example.Criteria criteria=example.createCriteria();
		if(StringUtils.isNotBlank(dName)) {
			criteria.andEqualTo("dname", dName);
		}
		if(StringUtils.isNotBlank(loc))
			criteria.andEqualTo("loc",loc);
		
		return deptMapper.selectByExample(example);
	}

	@Override
	public boolean deleteDept(long deptNo) {
		int num = -1;
		Example example= new Example(Dept.class);
		Example.Criteria criteria=example.createCriteria();
		criteria.andEqualTo("deptno",deptNo);
		num=deptMapper.deleteByExample(example);
		System.out.println(num);
		if(num>0) {
			return true;
		}
		return false;
	}


}
